#ifndef __CURSOR__
#define __CURSOR__
#define MIN_X 1
#define MIN_Y 1
#define MAX_Y 29
#define MAX_X 57
#define X_SPLIT 4
#define Y_SPLIT 2
#include <iostream>
#include <functional>
class Cursor{
	public:
	Cursor()
	{
		x=(MAX_X-MIN_X)/2+1;
		y=(MAX_Y-MIN_Y)/2+1;
		show();
	}
	enum Direction{
		UP,
		LEFT,
		DOWN,
		RIGHT,
	};
	void moveUp(void){
		if(y<=MIN_Y){
			return;
		}		
		y-=Y_SPLIT;
	}
	void moveLeft(void){
		if(x<=MIN_X){
			return;
		}
		x-=X_SPLIT;
	}
	void moveDown(void){
		if(y>=MAX_Y){
			return;
		}
		y+=Y_SPLIT;
	}
	void moveRight(void){
		if(x>=MAX_X){
			return;
		}
		x+=X_SPLIT;
	}
	void move(Direction dir){
		auto fun=func[dir];
		fun();
		show();
	}
	void show(){
		printf("\033[%d;%dH\033[0m",y,x);
	}
	int getX(){
		return x;
	}
	int getY(){return y;}
	private:
		int x;
		int y;
		function<void(void)> func[4]={
			bind(&Cursor::moveUp,this),
			bind(&Cursor::moveLeft,this),
			bind(&Cursor::moveDown,this),
			bind(&Cursor::moveRight,this),
		};
};

#endif
